<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/react/umd/react.development.js"></script>
    <script src="../node_modules/react-dom/umd/react-dom.development.js"></script>
    <script src="../node_modules/babel-standalone/babel.js"></script>
</head>
<body>
    <div id="app"></div>
    <script type="text/babel">
        class Cmp1 extends React.Component {
            constructor(props) {
                super(props);

                console.log('calling constructor');

                this.state = {
                    a: 5
                };
            }

            fn() {
                this.setState({
                    a: this.state.a + 1
                });
            }

            shouldComponentUpdate(nextProps, nextState) {
                
                return true;
            }

            componentWillMount() {
                console.log('will mount'); // 渲染前 即 render() 前
            }

            componentDidMount() {
                console.log('did mount'); // 渲染后
            }

            componentWillUpdate() {
                console.log('will update'); // 更新数据前 (state 改变或者父组件的 render() 改变)
            }

            componentDidUpdate() {
                console.log('did update'); // 更新数据后
            }

            componentWillUnmount() {
                console.log('will unmount'); // 组件卸载前调用
            }

            render() {
                return (
                    <div>
                        a={this.state.a}
                        <input type="button" value="+1" onClick={this.fn.bind(this)} />
                    </div>
                );
            }
        }

        ReactDOM.render(
            <Cmp1 />,
            document.getElementById('app')
        );

    </script>
</body>
</html>